<template>
  <div>
    <el-table
      :data="tableData"
      stripe
      border
      style="width: 100%"
    >
      <el-table-column
        align="center"
        prop="id"
        label="序号"
        width="80"
      >
        <template v-slot="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="name"
        label="名称"
        width="140"
      >
        <template v-slot="scope">
          <el-input v-model="scope.row.name" placeholder="名称" />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="phone"
        label="时间范围"
      >
        <template v-slot="scope">
          <el-date-picker
            v-model="scope.row.daterange"
            type="daterange"
            value-format="MM-dd"
            format="MM-dd"
            range-separator="~"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="water_height"
        label="计划湿润层深度"
        width="140"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.water_height" placeholder="计划湿润层深度">
            <template slot="append">cm</template>
          </el-input>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="kc"
        label="kc值"
        width="140"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.kc" placeholder="kc值">
            <template slot="append">%</template>
          </el-input>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="kc"
        label="kc值"
        width="140"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.kc" placeholder="kc值">
            <template slot="append">%</template>
          </el-input>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="kc"
        label="kc值"
        width="140"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.kc" placeholder="kc值">
            <template slot="append">%</template>
          </el-input>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="120">
        <template slot="header">
          <el-button size="mini" type="primary" @click="addRow">新增记录</el-button>
        </template>
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click="delRow(scope.row,scope.$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button v-if="tableData.length > 0" type="primary" style="margin-top:12px;" @click="submit">全部保存</el-button>
  </div>
</template>

<script>
import { deepClone } from '@/utils'
export default {
  props: {
    growthes: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      tableData: deepClone(this.growthes)
    }
  },
  methods: {
    addRow() {
      this.tableData.push({
        id: 1
      })
    },
    delRow(row, index) {
      this.tableData.splice(index, 1)
    },
    submit() {
      this.$emit('growthSubmit', this.tableData)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
